package com.repeat.submit;

import com.repeat.submit.filter.RepeatSubmitFilter;
import com.repeat.submit.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping;

import javax.annotation.Resource;

/**
 * @author : XiaGen
 * @Description: TODO
 * @date Date : 2021/11/25
 */
@Configuration
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
public class AutoRepeatSubmitConfig {

    @Value("${submit.token.name:token}")
    private String tokenName;

    @Resource
    private RequestMappingHandlerMapping requestMappingHandlerMapping;

    @Resource
    private RedisTemplate<String, String> redisTemplate;

    @Bean
    public RepeatSubmitFilter repeatSubmitFilter(){
        return new RepeatSubmitFilter(tokenName,requestMappingHandlerMapping,new RedisUtils(redisTemplate));
    }
}
